#Boa:Frame:frmPrincipal

import wx
from wx.lib.anchors import LayoutAnchors
import xml.dom.minidom

def create(parent):
    return frmPrincipal(parent)

[wxID_FRMPRINCIPAL, wxID_FRMPRINCIPALSBBAR, 
] = [wx.NewId() for _init_ctrls in range(2)]

[wxID_FRMPRINCIPALMNUSOBREMNUSOBRE] = [wx.NewId() for _init_coll_mnuSobre_Items in range(1)]

[wxID_FRMPRINCIPALMNUARQMNUSAIR] = [wx.NewId() for _init_coll_mnuArq_Items in range(1)]

[wxID_FRMPRINCIPALMNUMANMNUCADFER] = [wx.NewId() for _init_coll_mnuMan_Items in range(1)]

class frmPrincipal(wx.Frame):
    def _init_coll_mnuBarra_Menus(self, parent):
        # generated method, don't edit

        parent.Append(menu=self.mnuArq, title='Arquivo')
        parent.Append(menu=self.mnuTools, title='Ferramentas')
        parent.Append(menu=self.mnuMan, title='Manuten\xe7\xe3o')
        parent.Append(menu=self.mnuSobre, title='Ajuda')

    def _init_coll_mnuMan_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='Cadastra Ferramentas Forenses',
              id=wxID_FRMPRINCIPALMNUMANMNUCADFER, kind=wx.ITEM_NORMAL,
              text='Cadastro de Ferramentas')

    def _init_coll_mnuArq_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='', id=wxID_FRMPRINCIPALMNUARQMNUSAIR,
              kind=wx.ITEM_NORMAL, text='Sair')
        self.Bind(wx.EVT_MENU, self.OnMnuArqMnusairMenu,
              id=wxID_FRMPRINCIPALMNUARQMNUSAIR)

    def _init_coll_mnuSobre_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='', id=wxID_FRMPRINCIPALMNUSOBREMNUSOBRE,
              kind=wx.ITEM_NORMAL, text='Sobre')

    def _init_utils(self):
        # generated method, don't edit
        self.mnuBarra = wx.MenuBar()

        self.mnuArq = wx.Menu(title='')

        self.mnuSobre = wx.Menu(title='')

        self.mnuMan = wx.Menu(title='')

        self.mnuTools = wx.Menu(title='')

        self._init_coll_mnuBarra_Menus(self.mnuBarra)
        self._init_coll_mnuArq_Items(self.mnuArq)
        self._init_coll_mnuSobre_Items(self.mnuSobre)
        self._init_coll_mnuMan_Items(self.mnuMan)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRMPRINCIPAL, name='frmPrincipal',
              parent=prnt, pos=wx.Point(532, 355), size=wx.Size(400, 250),
              style=wx.MAXIMIZE_BOX | wx.DEFAULT_FRAME_STYLE,
              title='Myriad 0.1')
        self._init_utils()
        self.SetClientSize(wx.Size(384, 214))
        self.SetMenuBar(self.mnuBarra)

        self.sbbar = wx.StatusBar(id=wxID_FRMPRINCIPALSBBAR, name='sbbar',
              parent=self, style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.CarregaXMLTools()

    def OnMnuArqMnusairMenu(self, event):
        #event.Skip()
        self.Destroy()
        
    def CarregaXMLTools(self):
        self.doc = xml.dom.minidom.parse(r"c:\Forense\Myriad\Myriad_Tools.xml")

        #menuferramentas = wx.Menu()

        #adiciona o menuferramentas a barra

        #chama o menu dinamico apontando para o node barramenu
        self.MenuDinamico(self.mnuTools, self.doc.documentElement.childNodes[1])



    def MenuDinamico(self, pMenuPai, pNodePai):
        nodes = pNodePai.childNodes
        
        for node in nodes:
            if node.nodeName == "menu":
                print node.childNodes[0].nodeName
                titulo = node.getAttribute("item")
                resumo = node.getAttribute("res")
                #id = node.getAttribute("id")

                if node.getAttribute("toolbar") == "true":
                    pass
                    #self.CriaToolBarItem(titulo , id)           

                if (node.hasChildNodes()) and (node.childNodes[0].nodeName == "menu"):
                    #tem menus internos, entao esse eh um submenu
                    novo = wx.Menu()
                    pMenuPai.AppendMenu(wx.ID_ANY, titulo, novo)
                    self.MenuDinamico(novo, node)  
                else:
                    thismenu = pMenuPai.Append(wx.NewId(), titulo, resumo)
                    self.Bind(wx.EVT_MENU, lambda event, p=node: self.TrataClickMenus(event, p), thismenu)


    def TrataClickMenus(self, event, pnode):
        titulo = pnode.getAttribute("item")
        res = pnode.getAttribute("res")
        help = pnode.getAttribute("help")
        saida = pnode.getAttribute("output")
        execut = pnode.getAttribute("executavel")
        gui = (pnode.getAttribute("gui") == "true")
    
        print titulo
        #monta janela com itens 
        #se saiu com ok, executa o programa de acordo

    
